/*
 * POST방식의 한글처리
 * 1 POST방식을 처리해주는 클래스에 Filter인터페이스를 상속받는다.
 * 2 init(), doFilter()메소드를 오버라이딩 한다.
 * 3 web-inf/web.xml에서 환경설정
 *   <filter>
   <filter-name>CharacterFilter</filter-name>
   <filter-class>part7.CharacterFilter</filter-class>
    <init-param>
    	 <param-name>encoding</param-name>
		 <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  
  <filter-mapping>
  	<filter-name>CharacterFilter</filter-name>
	<url-Pattern>/*</url-Pattern>
  </filter-mapping>
 */


import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharacterFilter implements Filter{
	private String config;
	
	@Override
	public void init(FilterConfig config) throws ServletException {
     this.config =config.getInitParameter("encoding");
     if(config==null)
    	 this.config="UTF-8";
	}
	
	@Override
	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		req.setCharacterEncoding(config);
		resp.setCharacterEncoding(config);
		chain.doFilter(req, resp);
		
	}
	
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

}










